package com.bwie.policy;

import com.bwie.pojo.TbPolicy;
import com.bwie.utils.Result;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.kafka.core.KafkaTemplate;

public class RedPacketConText {


    IRedPolicy iRedPolicy;

    TbPolicy tbPolicy;

    public void setRedPolicy(TbPolicy tbPolicy, Integer userId, KafkaTemplate kafkaTemplate, StringRedisTemplate redisTemplate){
        this.tbPolicy=tbPolicy;

        //创建策略对象
        switch (tbPolicy.getPacketPeriod()){
            case 1:
                iRedPolicy=new WeekRedPacketPolicy(tbPolicy,userId,kafkaTemplate,redisTemplate);
                break;
            case 2:
                iRedPolicy=new DayRedPacketPolicy(tbPolicy,userId,kafkaTemplate,redisTemplate);
                break;
            case 3:
                iRedPolicy=new MonthRedPacketPolicy(tbPolicy,userId,kafkaTemplate,redisTemplate);
                break;
            case 4:
                iRedPolicy=new MultiRedPacketPolicy(tbPolicy,userId,kafkaTemplate,redisTemplate);
                break;
            default:
                iRedPolicy=new SingleRedPacketPolicy(tbPolicy,userId,kafkaTemplate,redisTemplate);
        }
    }

    public Result doGrabRedPacket(){
        return iRedPolicy.execute();
    }

}
